/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Base for creating a custom VGUI class; remove the functions you don't use.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/



local PANEL = {}
TIMER = nil

function PANEL:Init()
	//Create controls here
	
	self.MAP = ""
	self.CDTime = 0
	
	local Countdown = vgui.Create( "DLabel", self )
	local SP = self
		function Countdown:Think()
			Countdown:SetText( "Changing map to " .. SP.MAP .. " in " .. SP.CDTime .. " seconds." )
			Countdown:SizeToContents()
			Countdown:Center()
		end
end

function PANEL:PerformLayout()
	
	// Let's make sure we perform the layout of the class this panel is based on here as well.
	//self.BaseClass.PerformLayout( self )
	
	self:SetSize( 400, 40 )
	self:Center()
	self:AlignTop( ScrH() * 0.3 )
	
end

function PANEL:Paint()
	//Do Painting here
	//self.BaseClass.Paint( self )
	
	draw.RoundedBox( 4, 0, 0, self:GetWide(), self:GetTall(), Color( 0, 0, 0, 150 ) )

end

function PANEL:PaintOver()

	//Paint over self and child elements here.

end

function PANEL:Think()
	//Think stuff here

end

function PANEL:OnCursorEntered()

	//Do stuff when the cursor enters the panel

end

function PANEL:OnCursorExited()

	//Do Stuff when the cursor leaves the panel

end

function PANEL:OnMouseWheeled()

	//Do stuff when you wheel the mouse on this panel

end

function PANEL:OnMousePressed()

	//Do stuff when you press the mouse on this panel

end

function PANEL:OnMouseReleased()

	//Do stuff when you release the mouse on this panel

end

function PANEL:OnKeyCodePressed()

	//Do stuff when using keys from the keyboard on this panel. This hook uses the keycode enumerations
	//http://wiki.garrysmod.com/?title=P.OnKeyCodePressed	For more information

end

function PANEL:ActionSignal()

	//This is called on the parent frame when a child VGUI element is used. The key corresponds to what is set by Panel.SetCommand.
	//From the wiki
	
end

function PANEL:OnCursorMoved()

	//From the wiki
	//Called whenever the the mouse is moved within the panel.

end

function PANEL:DoClick()

	//For button type panels, use this. Called when you click the button.

end


//Register syntax - Desired element name, Panel to use, base class of the new element.
vgui.Register( "MapTimer", PANEL, "DPanel" )

function MapTimerHook( um )
	local MAPSTRING = um:ReadString()
	local MAPTIME = um:ReadLong()
	local DoRemove = um:ReadBool()
	
	if DoRemove then TIMER:Remove() return end
	
	TIMER = vgui.Create( "MapTimer" )
		TIMER.MAP = MAPSTRING
		function TIMER:Think()
			TIMER.CDTime = math.Clamp( MAPTIME - math.ceil(CurTime()), 0, 500000 )
		end
end
usermessage.Hook("MapTimerMESS", MapTimerHook)